/**
@author - Gyanendra Singh/ Suresh Chandra Pal
@version - 1.0 28/Feb/2009 
**/
//It will invoke as soon as user will start to write in the search box.
function clearText(form) {
	document.getElementById("searchValue").value = "";
}

//It will start the search
function startSearch() {

	if(searchablePages.match(currentPage) == null) {
		return true;
	}

	var searchValue = document.getElementById("searchValue").value;
	searchValue = trim(searchValue);
	if(((previousSearchPage == currentPage) && (searchValue == previousSearch))) {
		return false;
	}
	
	var params = 'searchValue=' + searchValue
				+ '&action=search';	
	
	previousSearchPage = currentPage;
	previousSearch = searchValue;
	loadContent(currentPage, params);
	
	return true;	    
}

//It will invoked when user will cancel the search
function cancelSearch() {
	var searchValue = document.getElementById("searchValue").value;
	if(searchValue == searchTextValue) {
		return false;
	}
	
	document.getElementById("searchValue").value = searchTextValue;
	previousSearch = "";
	if(searchablePages.match(currentPage) == null) {
		return true;
	}
	loadContent(currentPage);
}

//Used to reset the search box
function resetSearch() {
	document.getElementById("searchValue").value = searchTextValue;
	previousSearch = "";
}


/**
Function for implementing the sorting algo...
**/
function sortData(sortBy) {
	var sortOrder = 'ASC';
	var navTabs = document.getElementById("sorting"); 
	if(navTabs != null) {
		var selImage = navTabs.getElementsByTagName("img");		
	   	for(var i = 0; i < selImage.length; i++) {  
	   		var imgSrc = selImage[i].src; 
	   		var matchResult = imgSrc.match("upDark");
	   		if(matchResult) {
	   			sortOrder = 'DESC';
	   		} else {
	   			sortOrder = 'ASC';
	   		}
	   	}	
	}
	//alert(" sortBy: " + sortBy + " sortOrder: " + sortOrder)	
	var params = "sortBy=" + sortBy 
				+"&sortOrder=" + sortOrder
				+"&sorting=" + 'sorting';
	loadContent(currentPage, params);	

}

